package com.xmu.prcs.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Index;
/**
 * 帖子表
 * @author frequent
 *
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "post", uniqueConstraints = @UniqueConstraint(columnNames = "postname"))
@org.hibernate.annotations.Table(appliesTo = "post",
        indexes = {@Index(name = "idxPPN", columnNames = {"postname"}),
			@Index(name = "idxPLRT", columnNames = {"lastreplytime"})})
public class Post implements Serializable {
	
	private Integer idPost;
	private String autherName;//作者名
	private String postName;//帖子名
	private Integer replyNumber;//回复数
	private Integer browseNumber;//浏览数
	private String content;//帖子内容
	private Date createTime;//建立时间
	private String lastReplyUserName;//最后一次回复的用户名
	private Date lastReplyTime;//最后一次回复的时间	
	private Set<Reply> replys;//帖子下的回复
	
	public Post(){
		
	}
	
	public Post(Integer replyNumber, Integer browseNumber, Date createTime,
			String lastReplyUserName, Date lastReplyTime, String autherName){
		this.replyNumber = replyNumber;
		this.browseNumber = browseNumber;
		this.createTime = createTime;
		this.lastReplyUserName = lastReplyUserName;
		this.lastReplyTime = lastReplyTime;
		this.autherName = autherName;
	}

	@Id
	@GeneratedValue
	@Column(name = "idpost", unique = true, nullable = true)
	public Integer getIdPost() {
		return idPost;
	}

	public void setIdPost(Integer idPost) {
		this.idPost = idPost;
	}

	@Column(name = "replynumber")
	public Integer getReplyNumber() {
		return replyNumber;
	}

	public void setReplyNumber(Integer replyNumber) {
		this.replyNumber = replyNumber;
	}

	@Column(name = "browsenumber")
	public Integer getBrowseNumber() {
		return browseNumber;
	}

	public void setBrowseNumber(Integer browseNumber) {
		this.browseNumber = browseNumber;
	}

	@Column(name = "createtime")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "lastreplyusername", length = 20)
	public String getLastReplyUserName() {
		return lastReplyUserName;
	}

	public void setLastReplyUserName(String lastReplyUserName) {
		this.lastReplyUserName = lastReplyUserName;
	}

	@Column(name = "content", length = 1000)
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "lastreplytime")
	public Date getLastReplyTime() {
		return lastReplyTime;
	}

	public void setLastReplyTime(Date lastReplyTime) {
		this.lastReplyTime = lastReplyTime;
	}

	@Column(name = "authername", length = 20)
	public String getAutherName() {
		return autherName;
	}

	public void setAutherName(String autherName) {
		this.autherName = autherName;
	}

	@Column(name = "postname", length = 30)
	public String getPostName() {
		return postName;
	}

	public void setPostName(String postName) {
		this.postName = postName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "idpost")
	public Set<Reply> getReplys() {
		return replys;
	}

	public void setReplys(Set<Reply> replys) {
		this.replys = replys;
	}
	
}
